/*
 * $Id: RequestTypeDAO.java,v 1.11 2009/09/28 14:49:00 navdeep_mahajan Exp $
 * 
 * Copyright (C) 2006 General Electric Company. All Rights Reserved.
 * 
 * This software is the confidential and proprietary information of the General
 * Electric Company (GE). You shall not disclose this software and shall use it
 * only in accordance with the terms of the license agreement you entered into
 * with GE.
 * 
 * GE MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
 * NON-INFRINGEMENT. GE SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
 * AS A RESULT OF USING, MODIFYING, OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES.
 */
package com.ge.healthcare.autosc.common.database.dao;

import java.util.HashMap;
import java.util.List;

import com.ge.healthcare.autosc.common.ASCUtil;
import com.ge.healthcare.autosc.common.database.pojo.ActRequestList;
import com.ge.healthcare.autosc.common.database.pojo.CfgRequestType;

/**
 * @author 212042764 (But Bill Oliver created this) =)
 * 
 */
public class RequestTypeDAO extends BaseDAO implements IRequestTypeDAO {

	/**
	 * Eclipse generated
	 */
	private static final long serialVersionUID = -4419083025057062900L;
	private IRequestListDAO requestListDAO = null;

	public RequestTypeDAO() {
		super(CfgRequestType.TABLE_NAME);
	}

	public void setActRequestListDAO(IRequestListDAO requestListDAO) {
		this.requestListDAO = requestListDAO;
	}

	public CfgRequestType getRequestTypeByRequestListId(Long requestListId) {
		ActRequestList requestList = requestListDAO
				.getRequestListByID(requestListId);
		if (!ASCUtil.isNullOrEmptyObject(requestList)) {
			return getRequestTypeByID(requestList.getRequestTypeId());
		}
		return null;
	}

	public CfgRequestType getRequestTypeByID(Long requestTypeId) {
		Object requestType = findObjectByID(CfgRequestType.COL_REQUEST_TYPE_ID,
				requestTypeId);
		if (!ASCUtil.isNullOrEmptyObject(requestType)) {
			return (CfgRequestType) requestType;
		}
		return null;
	}

	public CfgRequestType getRequestTypeByName(String requestTypeName) {
		Object requestType = findObjectByID(
				CfgRequestType.COL_REQUEST_TYPE_NAME, requestTypeName);
		if (!ASCUtil.isNullOrEmptyObject(requestType)) {
			return (CfgRequestType) requestType;
		}
		return null;
	}

	/**
	 * @param requestTypeName
	 * @return
	 */
	public CfgRequestType getRequestableRequestTypeByName(String requestTypeName) {
		HashMap<String, Object> queryValues = new HashMap<String, Object>();
		queryValues.put(CfgRequestType.COL_REQUEST_TYPE_NAME, requestTypeName);
		queryValues.put(CfgRequestType.COL_IS_REQUESTABLE, "Y");
		List<?> requestTypeLst = findByProperties(queryValues);
		if (!ASCUtil.isNullOrEmptyList(requestTypeLst)) {
			return (CfgRequestType) requestTypeLst.get(0);
		}
		return null;
	}

	/**
	 * @see com.ge.healthcare.autosc.common.database.dao.BaseDAO#save(java.lang.Object)
	 */
	public void save(Object pojo) {
		super.save(pojo);
	}

	/**
	 * @see com.ge.healthcare.autosc.common.database.dao.IRequestTypeDAO#saveAlways(java.lang.Object)
	 */
	public void saveAlways(Object pojo) {
		super.save(pojo);
	}

	/**
	 * @see com.ge.healthcare.autosc.common.database.dao.BaseDAO#deleteByID(java.lang.Object)
	 */
	public void deleteByID(Object pojo) {
		super.deleteByID(pojo);
	}

	/**
	 * @see com.ge.healthcare.autosc.common.database.dao.BaseDAO#refresh(java.lang.Object)
	 */
	public void refresh(Object pojo) {
		super.refresh(pojo);
	}

}
